package com.chixing.day03;

/**
 * @author Y2014188432
 */
public class Person {
    public String name;
    public char gender;
    public int age;
    public boolean marry;

    public Person() {
    }

    public Person(String name, char gender, int age, boolean marry) {
        this.name = name;
        this.gender = gender;
        this.age = age;
        this.marry = marry;
    }

    /**
     * 判断该个体与另一个体是否达到结婚要求
     * @param person 另一个体
     * @return 能 / 不能 ( true / false )
     */
    public boolean can(Person person){
        if(person == null || person == this){
            return false;
        }
        return isUnmarried(marry, person.marry) && isDifferent(gender, person.gender) && ageIsLawful(age, gender) && ageIsLawful(person.age, person.gender);
    }

    /**
     * 判断两个体是否均为未婚状态
     * @param marry1 个体1
     * @param marry2 个体2
     * @return 是 / 否 ( true / false )
     */
     public boolean isUnmarried(boolean marry1,boolean marry2){
        return !marry1 && !marry2;
     }

    /**
     * 判断两个体是否为异性
     * @param gender1 个体1
     * @param gender2 个体2
     * @return 是 / 否 ( true / false )
     */
     public boolean isDifferent(char gender1 , char gender2){
        return gender1 != gender2;
     }

    /**
     * 判断个体是否达到结婚年龄要求
     * @param age 当前年龄
     * @param gender 性别
     * @return 是 / 否 ( true / false )
     */
     public boolean ageIsLawful(int age,char gender){
        if('男' == gender && age >= 24){
            return true;
        }return '女' == gender && age >= 22;
     }
}
